package control;
import model.*;
import db.*;

import java.util.ArrayList;

public class SupplierCtrl
{
	DBSupplier dbSup = new DBSupplier();
	
	public SupplierCtrl()
	{
		
	}
	
	public ArrayList<Supplier> getAllSuppliers()
	{
		ArrayList<Supplier> allSup = new ArrayList<Supplier>();
		allSup = dbSup.getAllSuppliers(false);
		return allSup;
	}
	
	public Supplier getSupplierPhoneNo(String phoneno)
	{
		return dbSup.getSupplierPhoneNo(phoneno, true);
	}
	
	public Supplier getSupplierName(String name)
	{
		return dbSup.getSupplierName(name, true);
	}
	
	public void insertSupplier(String name, String address, String country, int phoneno, String email) throws Exception
	{
		Supplier toInsert = new Supplier();
		toInsert.setName(name);
		toInsert.setAddress(address);
		toInsert.setCountry(country);
		toInsert.setPhoneno(phoneno);
		toInsert.setEmail(email);
		dbSup.insertSupplier(toInsert);
	}
	
	public int updateSupplier(String name, String address, String country, int phoneno, String email)
	{
		Supplier sup = new Supplier();
		sup.setName(name);
		sup.setAddress(address);
		sup.setCountry(country);
		sup.setPhoneno(phoneno);
		sup.setEmail(email);
		return dbSup.updateSupplier(sup);
	}
	
	public void deleteSupplier(String phoneno)
	{
		dbSup.deleteSupplier(phoneno);
	}
}
